<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
	$(function(){
		$("#forgetIdBtn").click(function(){
			var email=$("#email").val();
			$.ajax({
				type:"POST",
				url:"${initParam.root}/wedding.do",
				data:"command=findId&email="+email,
				dataType:"json",
				success:function(data){
					if(data.id==null){
						alert("메일주소를 확인해주세요!");
						return;
					}
						$("#result").html("회원님의 아이디는 "+data.id+" 입니다.").css({'color' : 'purple','font-size' : '12' , 'font-weight' : 'bolder'});
					
					
				}
			});
		});
		$("#forgetPass").click(function(){
			var myId = $("#myId").val();
			$.ajax({
				type:"POST",
				url:"${initParam.root}/wedding.do",
				data:"command=showHint&id="+myId,
				dataType:"json",
				success:function(data){
					var hintVal=data.hint;
					var hintTxt="";
					if(hintVal==0){
						alert("아이디를 정확히 입력해주세요!");
						return;
					}
						switch (hintVal){
						case 1: hintTxt="출신 고등학교 이름은?";
						break;
						case 2: hintTxt="가장 좋아했던 선생님 성함은?";
						break;
						case 3: hintTxt="가장 좋아하는 색깔은?";
						break;
						case 4: hintTxt="사랑하는 사람 이름은?";
						break;
						case 5: hintTxt="가장 좋아하는 음식은?";
						break;
						case 6: hintTxt="가장 좋아하는 영화는?";
						break;
						}	
					$("#result2").html(hintTxt+"<br><input type='text' id='answerTxt'><input type='button' value='전송' id='getPass'>").css({'color' : 'purple','font-size' : '12' , 'font-weight' : 'bolder'});
					}
						
				
			});
		});
		$("#result2").on("click","#getPass",function(){
			$.ajax({
				type:"POST",
				url:"${initParam.root}/wedding.do",
				data:"command=getPass&id="+$("#myId").val()+"&answer="+$("#answerTxt").val(),
				dataType:"json",
				success:function(data){
					if(data.password==null){
						alert("비밀번호 정답이 일치하지 않습니다!");
					}
					$("#result3").html("패스워드는 "+data.password+" 입니다.").css({'color' : 'orange','font-size' : '12' , 'font-weight' : 'bolder'});;
				}
			});
		});
	});
</script>
<style type="text/css">
	body{
		background-image : url("${initParam.root}/img/popup_back.jpg");
	}
</style>
<table>
<tr>
	<td colspan="3" align="left"><font color="red"><b>아이디 찾기</b></font></td>
</tr>
<tr>
<td align="center"><font style="font-size: 12px" color="gray">이메일</font></td><td><input type="text" name="email" id="email"></td><td><input type="button" value="찾기" id="forgetIdBtn"></td>
</tr>
<tr>
<td colspan="3" align="center"><span id="result"></span></td>
</tr>
<tr>
	<td colspan="3" align="left"><font color="red"><b>비밀번호 찾기</b></font></td>
</tr>
<tr>
<td align="center"><font style="font-size: 12px" color="gray">아이디입력</font></td><td><input type="text" name="myId" id="myId"></td>
<td ><input type="button" value="비밀번호찾기" id="forgetPass"></td>
</tr>
<tr>
<td colspan="3"><span id="result2"></span></td>
</tr>
<tr>
<td colspan="3"><span id="result3"></span></td>
</tr>
<tr>
<td colspan="3" align="right">
<input type="button" value="닫기" id="popupClose" onclick='javascript:self.close()'>
</td>
</tr>
</table>